/**
 * @program: leetcode33
 * @author: JCM
 * @create: 2023-03-03 21:43
 * @description:
 **/
public class Main {
    public int search(int[] nums, int t) {
        int len = nums.length-1;
        if(len == 0) {
            return t == nums[0] ? 0 : -1;
        }
        int l = 0, r = len;
        while(l <= r) {
            int mid = (l+r)/2;
            if(nums[mid] == t) {
                return mid;
            }
            if(nums[0] <= nums[mid]) {
                if(t < nums[mid] && t >= nums[0]) {
                    r = mid - 1;
                }else {
                    l = mid + 1;
                }
            }else {
                if(t > nums[mid] && t <= nums[len]) {
                    l = mid + 1;
                }else {
                    r = mid - 1;
                }
            }
        }
        return -1;
    }
}
